package com.dhcc.bpm.business.utils;

import java.util.HashMap;
import java.util.Map;

public enum Status {

    // business
    BUSINESS_SUCCESS("0000", "交易成功"),
    BUSINESS_FAIL("0001", "交易失败"),
    BUSINESS_RUSH_ERROR("0002", "冲正失败"),
    BUSINESS_FAIL_RUSH_ERROR("0003", "交易失败，自动冲正失败"),
    BUSINESS_FAIL_RUSH_SUCCESS("0004", "交易失败，自动冲正成功"),
    BUSINESS_SIGN_CONTRACT_ERROR("0005", "该用户已签约，不能重复签约"),
    BUSINESS_TERMINATE_ERROR("0006", "该用户没有签约记录，不能进行解约操作"),
    BUSINESS_CHECK_OUT("0007", "该产品已关闭"),
    // file
    FILE_OPEN_ERROR("F100", "打开文件错误"),
    FILE_DOWNLOAD_ERROR("F101", "下载文件失败"),
    FILE_UPLOAD_ERROR("F102", "上传文件失败"),
    FILE_ANALYZE_ERROR("F103", "解析文件失败"),
    FILE_BUILD_ERROR("F104", "生成文件失败"),
    FILE_READ_ERROR("F105", "读取文件内容失败"),
    FILE_NOT_EXIST_ERROR("F106", "文件不存在"),
    FILE_NO_CONTENT_ERROR("F107", "文件内容为空"),
    FILE_CREATE_DIRECTORY_ERROR("F108", "创建文件目录失败"),
    // db
    DB_SELECT_ERROR("D200", "数据库查询失败"),
    //添加查询成功码 2019年12月13日18:31:49

    DB_SELECT_SUCCESS("0000", "数据库查询成功"),
    DB_UPDATE_ERROR("D201", "数据库更新失败"),
    DB_DELETE_ERROR("D202", "数据库删除失败"),
    DB_INSERT_ERROR("D203", "数据库插入失败"),
    //添加插入成功码 2019年12月14日17:38:29
    DB_INSERT_SUCCESS("0000", "数据库插入成功"),
    DB_SUBMIT_ERROR("D204", "数据提交失败"),
    DB_UN_RECORD_ERROR("D205", "无查询记录"),
    DB_MAPPING_ERROR("D206", "数据映射失败"),
    DB_DEFINE_VERNIER_ERROR("D207", "定义游标失败"),
    DB_READ_VERNIER_ERROR("D208", "获取游标失败"),
    // communicate
    COMMUNICATE_ERROR("T300", "通讯异常"),
    COMMUNICATE_TIMEOUT_ERROR("T301", "通讯超时"),
    COMMUNICATE_FTP_CONNECT_ERROR("T302", "FTP连接错误"),
    COMMUNICATE_FTP_AUTHENTICATE_ERROR("T303", "FTP登录用户或密码错误"),
    COMMUNICATE_FTP_DECODE_PASSWORD_ERROR("T304", "FTP登录密码解密失败"),
    COMMUNICATE_SERVICE_TIMEOUT_ERROR("T305", "服务内部超时"),
    COMMUNICATE_THIRD_PARTY_TIMEOUT_ERROR("T306", "请求三方超时"),
    //check
    CHECK_REPEAT_ERROR("C400", "重复交易"),
    CHECK_DATA_ITEM_ERROR("C401", "报文数据项检查失败"),
    CHECK_MAC_ERROR("C402", "MAC校验失败"),
    CHECK_DATA_TYPE_ERROR("C403", "数据类型非法"),
    CHECK_THIRD_PARTY_RETURN_ERROR("C404", "第三方返回失败!已自动到核心冲正"),
    CHECK_PRODUCT_NO_CODE_ERROR("C405", "产品代码未赋值"),
    CHECK_PRODUCT_STATUS_CLOSE_ERROR("C406", "产品或渠道状态未启用"),
    CHECK_PRODUCT_OUT_OF_OPEN_TIME_ERROR("C407", "产品或渠道不在开通时间范围内"),
    CHECK_SYSTEM_FUNCTION_ERROR("C408", "系统函数执行失败"),
    CHECK_NULL_VARIABLE_ERROR("C409", "变量不能为空"),
    CHECK_BATCH_TASK_ERROR("C410", "批扣任务已经执行"),
    CHECK_DATA_FORMAT_ERROR("C411", "报文格式不正确"),
    //gateway
    GATEWAY_ANALYZE_ERROR("G500", "拆包异常"),
    GATEWAY_INTEGRATE_ERROR("G501", "组包异常"),
    GATEWAY_REQUEST_TYPE_ERROR("G502", "不支持的请求方式"),
    GATEWAY_TOKEN_AUTHENTICATION_ERROR("G503", "鉴权失败"),
    GATEWAY_TOKEN_TIMEOUT_ERROR("G504", "token已失效"),
    GATEWAY_NO_TOKEN_ERROR("G505", "返回认证token"),
    GATEWAY_NOT_FOUND_SERVICE_ERROR("G506", "未找到服务"),
    GATEWAY_FORWARD_ERROR("G507", "转发异常"),
    GATEWAY_DECRYPT_ERROR("G508", "解密失败"),
    GATEWAY_ENCRYPT_ERROR("G509", "加密失败"),
    GATEWAY_CHECK_HEADER_ERROR("G510", "请求头缺少必传项"),
    GATEWAY_CHECK_PLUGIN_ERROR("G511", "加解密插件不存在"),
    GATEWAY_SIGN_ERROR("G512", "签名失败"),
    GATEWAY_SIGN_VERITY_ERROR("G513", "验签失败"),
    GATEWAY_CONFIG_NOT_FOUND_ERROR("G514", "未找到配置");

    private String code;
    private String msg;

    private Status(String code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public static String getMsgByCode(String code) {
        return enumManager.map.get(code);
    }

    private static class enumManager {
        private static final Map<String, String> map = new HashMap<String, String>();

        static {
            Status[] values = Status.values();
            for (Status status : values) {
                map.put(status.getCode(), status.getMsg());
            }
        }
    }
}
